import XtxConfirm from './confirm.vue'

import {h,render} from 'vue'

const div = document.createElement('div')
div.setAttribute('class','xtx-confirm-container')
document.body.appendChild(div)

type props = {
    title?:string
    text:string
}

export default function Confirm({title,text}:props){
    // h(组件,属性)创建虚拟dom   render() 渲染虚拟dom

    // <XtxConfirm title='我是大标师' text='我是内容'cancelCallback=confirmCallback ></XtxConfirm>

    return new Promise((resolve,reject)=>{
        const confirmCallback = ()=>{
            // console.log("确认");
            resolve(undefined)
            render(null,div)
        }
    
        const cancelCallback = ()=>{
            // console.log("取消");
            reject()
            render(null,div)
        }
    
        const vNode = h(XtxConfirm,{title,text,cancelCallback,confirmCallback})
        render(vNode,div)
    })
}